import CryptoJS from "crypto-js";

const key = import.meta.env.VITE_LOGIN_CRYPTO_KEY;

const encrypt = (data: string) => {
  const encrypted = CryptoJS.AES.encrypt(data, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
};

const decrypt = (data: string) => {
  const decrypt = CryptoJS.AES.decrypt(data, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
};

export default {
  encrypt,
  decrypt
};
